8259778: Merge MutableSpace and ImmutableSpace

Reviewed-by: sspitsyn, dholmes, tschatzl
This commit is contained in:
Kim Barrett 2021-01-29 03:49:57 +00:00
parent 251c6419bf
commit ea2c4474be
8 changed files with 68 additions and 275 deletions

View File

@ -1,83 +0,0 @@
/*
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "gc/parallel/immutableSpace.hpp"
#include "memory/iterator.inline.hpp"
#include "memory/universe.hpp"
#include "oops/oop.inline.hpp"
#include "utilities/macros.hpp"
void ImmutableSpace::initialize(MemRegion mr) {
HeapWord* bottom = mr.start();
HeapWord* end = mr.end();
assert(Universe::on_page_boundary(bottom) && Universe::on_page_boundary(end),
"invalid space boundaries");
_bottom = bottom;
_end = end;
}
void ImmutableSpace::oop_iterate(OopIterateClosure* cl) {
HeapWord* obj_addr = bottom();
HeapWord* t = end();
// Could call objects iterate, but this is easier.
while (obj_addr < t) {
obj_addr += oop(obj_addr)->oop_iterate_size(cl);
}
}
void ImmutableSpace::object_iterate(ObjectClosure* cl) {
HeapWord* p = bottom();
while (p < end()) {
cl->do_object(oop(p));
p += oop(p)->size();
}
}
#ifndef PRODUCT
void ImmutableSpace::print_short() const {
tty->print(" space " SIZE_FORMAT "K, 100%% used", capacity_in_bytes() / K);
}
void ImmutableSpace::print() const {
print_short();
tty->print_cr(" [" INTPTR_FORMAT_W(#-6) "," INTPTR_FORMAT_W(#-6) ")", p2i(bottom()), p2i(end()));
}
#endif
void ImmutableSpace::verify() {
HeapWord* p = bottom();
HeapWord* t = end();
HeapWord* prev_p = NULL;
while (p < t) {
oopDesc::verify(oop(p));
prev_p = p;
p += oop(p)->size();
}
guarantee(p == end(), "end of last object must match end of space");
}

View File

@ -1,71 +0,0 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_GC_PARALLEL_IMMUTABLESPACE_HPP
#define SHARE_GC_PARALLEL_IMMUTABLESPACE_HPP
#include "memory/iterator.hpp"
// An ImmutableSpace is a viewport into a contiguous range
// (or subrange) of previously allocated objects.
// Invariant: bottom() and end() are on page_size boundaries and
// bottom() <= end()
class ImmutableSpace: public CHeapObj<mtGC> {
friend class VMStructs;
protected:
HeapWord* _bottom;
HeapWord* _end;
public:
ImmutableSpace() { _bottom = NULL; _end = NULL; }
HeapWord* bottom() const { return _bottom; }
HeapWord* end() const { return _end; }
MemRegion region() const { return MemRegion(bottom(), end()); }
// Initialization
void initialize(MemRegion mr);
bool contains(const void* p) const { return _bottom <= p && p < _end; }
// Size computations. Sizes are in bytes.
size_t capacity_in_bytes() const { return capacity_in_words() * HeapWordSize; }
// Size computations. Sizes are in heapwords.
size_t capacity_in_words() const { return pointer_delta(end(), bottom()); }
virtual size_t capacity_in_words(Thread*) const { return capacity_in_words(); }
// Iteration.
virtual void oop_iterate(OopIterateClosure* cl);
virtual void object_iterate(ObjectClosure* cl);
// Debugging
virtual void print() const PRODUCT_RETURN;
virtual void print_short() const PRODUCT_RETURN;
virtual void verify();
};
#endif // SHARE_GC_PARALLEL_IMMUTABLESPACE_HPP

View File

@ -35,7 +35,14 @@
#include "utilities/align.hpp"
#include "utilities/macros.hpp"
MutableSpace::MutableSpace(size_t alignment): ImmutableSpace(), _alignment(alignment), _top(NULL) {
MutableSpace::MutableSpace(size_t alignment) :
_mangler(NULL),
_last_setup_region(),
_alignment(alignment),
_bottom(NULL),
_top(NULL),
_end(NULL)
{
assert(MutableSpace::alignment() % os::vm_page_size() == 0,
"Space should be aligned");
_mangler = new MutableSpaceMangler(this);

View File

@ -25,26 +25,30 @@
#ifndef SHARE_GC_PARALLEL_MUTABLESPACE_HPP
#define SHARE_GC_PARALLEL_MUTABLESPACE_HPP
#include "gc/parallel/immutableSpace.hpp"
#include "memory/allocation.hpp"
#include "memory/iterator.hpp"
#include "memory/memRegion.hpp"
#include "utilities/copy.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"
class WorkGang;
// A MutableSpace is a subtype of ImmutableSpace that supports the
// concept of allocation. This includes the concepts that a space may
// be only partially full, and the query methods that go with such
// an assumption. MutableSpace is also responsible for minimizing the
// A MutableSpace supports the concept of allocation. This includes the
// concepts that a space may be only partially full, and the query methods
// that go with such an assumption.
//
// MutableSpace is also responsible for minimizing the
// page allocation time by having the memory pretouched (with
// AlwaysPretouch) and for optimizing page placement on NUMA systems
// by make the underlying region interleaved (with UseNUMA).
//
// Invariant: (ImmutableSpace +) bottom() <= top() <= end()
// top() is inclusive and end() is exclusive.
// Invariant: bottom() <= top() <= end()
// top() and end() are exclusive.
class MutableSpaceMangler;
class MutableSpace: public ImmutableSpace {
class MutableSpace: public CHeapObj<mtGC> {
friend class VMStructs;
// Helper for mangling unused space in debug builds
@ -52,8 +56,9 @@ class MutableSpace: public ImmutableSpace {
// The last region which page had been setup to be interleaved.
MemRegion _last_setup_region;
size_t _alignment;
protected:
HeapWord* _bottom;
HeapWord* volatile _top;
HeapWord* _end;
MutableSpaceMangler* mangler() { return _mangler; }
@ -67,17 +72,25 @@ class MutableSpace: public ImmutableSpace {
MutableSpace(size_t page_size);
// Accessors
HeapWord* bottom() const { return _bottom; }
HeapWord* top() const { return _top; }
HeapWord* end() const { return _end; }
void set_bottom(HeapWord* value) { _bottom = value; }
virtual void set_top(HeapWord* value) { _top = value; }
void set_end(HeapWord* value) { _end = value; }
HeapWord* volatile* top_addr() { return &_top; }
HeapWord** end_addr() { return &_end; }
virtual void set_bottom(HeapWord* value) { _bottom = value; }
virtual void set_end(HeapWord* value) { _end = value; }
size_t alignment() { return _alignment; }
MemRegion region() const { return MemRegion(bottom(), end()); }
size_t capacity_in_bytes() const { return capacity_in_words() * HeapWordSize; }
size_t capacity_in_words() const { return pointer_delta(end(), bottom()); }
virtual size_t capacity_in_words(Thread*) const { return capacity_in_words(); }
// Returns a subregion containing all objects in this space.
MemRegion used_region() { return MemRegion(bottom(), top()); }
@ -92,10 +105,6 @@ class MutableSpace: public ImmutableSpace {
WorkGang* pretouch_gang = NULL);
virtual void clear(bool mangle_space);
// Does the usual initialization but optionally resets top to bottom.
#if 0 // MANGLE_SPACE
void initialize(MemRegion mr, bool clear_space, bool reset_top);
#endif
virtual void update() { }
virtual void accumulate_statistics() { }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
#ifndef SHARE_GC_PARALLEL_SPACECOUNTERS_HPP
#define SHARE_GC_PARALLEL_SPACECOUNTERS_HPP
#include "gc/parallel/immutableSpace.hpp"
#include "gc/parallel/mutableSpace.hpp"
#include "gc/shared/generationCounters.hpp"
#include "runtime/perfData.hpp"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
#ifndef SHARE_GC_PARALLEL_VMSTRUCTS_PARALLELGC_HPP
#define SHARE_GC_PARALLEL_VMSTRUCTS_PARALLELGC_HPP
#include "gc/parallel/immutableSpace.hpp"
#include "gc/parallel/mutableSpace.hpp"
#include "gc/parallel/parallelScavengeHeap.hpp"
#include "gc/parallel/psOldGen.hpp"
@ -46,9 +45,8 @@
nonstatic_field(PSVirtualSpace, _committed_low_addr, char*) \
nonstatic_field(PSVirtualSpace, _committed_high_addr, char*) \
\
nonstatic_field(ImmutableSpace, _bottom, HeapWord*) \
nonstatic_field(ImmutableSpace, _end, HeapWord*) \
\
nonstatic_field(MutableSpace, _bottom, HeapWord*) \
nonstatic_field(MutableSpace, _end, HeapWord*) \
volatile_nonstatic_field(MutableSpace, _top, HeapWord*) \
\
nonstatic_field(PSYoungGen, _reserved, MemRegion) \
@ -81,8 +79,7 @@
declare_type(ParallelScavengeHeap, CollectedHeap) \
\
declare_toplevel_type(PSVirtualSpace) \
declare_toplevel_type(ImmutableSpace) \
declare_type(MutableSpace, ImmutableSpace) \
declare_toplevel_type(MutableSpace) \
declare_toplevel_type(PSYoungGen) \
declare_toplevel_type(PSOldGen) \
\
@ -91,7 +88,6 @@
/*****************************/ \
\
declare_toplevel_type(PSVirtualSpace*) \
declare_toplevel_type(ImmutableSpace*) \
declare_toplevel_type(MutableSpace*) \
declare_toplevel_type(PSYoungGen*) \
declare_toplevel_type(PSOldGen*) \

View File

@ -1,92 +0,0 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
package sun.jvm.hotspot.gc.parallel;
import java.io.*;
import java.util.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.memory.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.utilities.Observable;
import sun.jvm.hotspot.utilities.Observer;
public abstract class ImmutableSpace extends VMObject {
static {
VM.registerVMInitializedObserver(new Observer() {
public void update(Observable o, Object data) {
initialize(VM.getVM().getTypeDataBase());
}
});
}
private static synchronized void initialize(TypeDataBase db) {
Type type = db.lookupType("ImmutableSpace");
bottomField = type.getAddressField("_bottom");
endField = type.getAddressField("_end");
}
public ImmutableSpace(Address addr) {
super(addr);
}
// Fields
private static AddressField bottomField;
private static AddressField endField;
// Accessors
public Address bottom() { return bottomField.getValue(addr); }
public Address end() { return endField.getValue(addr); }
/** Returns a subregion of the space containing all the objects in
the space. */
public MemRegion usedRegion() {
return new MemRegion(bottom(), end());
}
/** Support for iteration over heap -- not sure how this will
interact with GC in reflective system, but necessary for the
debugging mechanism */
public OopHandle bottomAsOopHandle() {
return bottomField.getOopHandle(addr);
}
/** returns all MemRegions where live objects are */
public abstract List<MemRegion> getLiveRegions();
/** Returned value is in bytes */
public long capacity() { return end().minus(bottom()); }
public abstract long used();
/** Testers */
public boolean contains(Address p) {
return (bottom().lessThanOrEqual(p) && end().greaterThan(p));
}
public void print() { printOn(System.out); }
public abstract void printOn(PrintStream tty);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,7 +34,7 @@ import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.utilities.Observable;
import sun.jvm.hotspot.utilities.Observer;
public class MutableSpace extends ImmutableSpace {
public class MutableSpace extends VMObject {
static {
VM.registerVMInitializedObserver(new Observer() {
public void update(Observable o, Object data) {
@ -45,6 +45,8 @@ public class MutableSpace extends ImmutableSpace {
private static synchronized void initialize(TypeDataBase db) {
Type type = db.lookupType("MutableSpace");
bottomField = type.getAddressField("_bottom");
endField = type.getAddressField("_end");
topField = type.getAddressField("_top");
}
@ -53,9 +55,13 @@ public class MutableSpace extends ImmutableSpace {
}
// Fields
private static AddressField bottomField;
private static AddressField endField;
private static AddressField topField;
// Accessors
public Address bottom() { return bottomField.getValue(addr); }
public Address end() { return endField.getValue(addr); }
public Address top() { return topField.getValue(addr); }
/** In bytes */
@ -63,6 +69,22 @@ public class MutableSpace extends ImmutableSpace {
return top().minus(bottom());
}
/** Returned value is in bytes */
public long capacity() { return end().minus(bottom()); }
/** Returns a subregion of the space containing all the objects in
the space. */
public MemRegion usedRegion() {
return new MemRegion(bottom(), end());
}
/** Support for iteration over heap -- not sure how this will
interact with GC in reflective system, but necessary for the
debugging mechanism */
public OopHandle bottomAsOopHandle() {
return bottomField.getOopHandle(addr);
}
/** returns all MemRegions where live objects are */
public List<MemRegion> getLiveRegions() {
List<MemRegion> res = new ArrayList<>();
@ -70,6 +92,12 @@ public class MutableSpace extends ImmutableSpace {
return res;
}
/** Testers */
public boolean contains(Address p) {
return (bottom().lessThanOrEqual(p) && end().greaterThan(p));
}
public void print() { printOn(System.out); }
public void printOn(PrintStream tty) {
tty.print(" [" + bottom() + "," +
top() + "," + end() + "] ");