Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/memory/barrierSet.hpp
32285 views
/*1* Copyright (c) 2000, 2012, 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_VM_MEMORY_BARRIERSET_HPP25#define SHARE_VM_MEMORY_BARRIERSET_HPP2627#include "memory/memRegion.hpp"28#include "oops/oopsHierarchy.hpp"2930// This class provides the interface between a barrier implementation and31// the rest of the system.3233class BarrierSet: public CHeapObj<mtGC> {34friend class VMStructs;35public:36enum Name {37ModRef,38CardTableModRef,39CardTableExtension,40G1SATBCT,41G1SATBCTLogging,42ShenandoahBarrierSet,43Other,44Uninit45};4647enum Flags {48None = 0,49TargetUninitialized = 150};51protected:52int _max_covered_regions;53Name _kind;5455public:5657BarrierSet() { _kind = Uninit; }58// To get around prohibition on RTTI.59BarrierSet::Name kind() { return _kind; }60virtual bool is_a(BarrierSet::Name bsn) = 0;6162// These operations indicate what kind of barriers the BarrierSet has.63virtual bool has_read_ref_barrier() = 0;64virtual bool has_read_prim_barrier() = 0;65virtual bool has_write_ref_barrier() = 0;66virtual bool has_write_ref_pre_barrier() = 0;67virtual bool has_write_prim_barrier() = 0;6869// These functions indicate whether a particular access of the given70// kinds requires a barrier.71virtual bool read_ref_needs_barrier(void* field) = 0;72virtual bool read_prim_needs_barrier(HeapWord* field, size_t bytes) = 0;73virtual bool write_prim_needs_barrier(HeapWord* field, size_t bytes,74juint val1, juint val2) = 0;7576// The first four operations provide a direct implementation of the77// barrier set. An interpreter loop, for example, could call these78// directly, as appropriate.7980// Invoke the barrier, if any, necessary when reading the given ref field.81virtual void read_ref_field(void* field) = 0;8283// Invoke the barrier, if any, necessary when reading the given primitive84// "field" of "bytes" bytes in "obj".85virtual void read_prim_field(HeapWord* field, size_t bytes) = 0;8687// Invoke the barrier, if any, necessary when writing "new_val" into the88// ref field at "offset" in "obj".89// (For efficiency reasons, this operation is specialized for certain90// barrier types. Semantically, it should be thought of as a call to the91// virtual "_work" function below, which must implement the barrier.)92// First the pre-write versions...93template <class T> inline void write_ref_field_pre(T* field, oop new_val);94private:95// Keep this private so as to catch violations at build time.96virtual void write_ref_field_pre_work( void* field, oop new_val) { guarantee(false, "Not needed"); };97protected:98virtual void write_ref_field_pre_work( oop* field, oop new_val) {};99virtual void write_ref_field_pre_work(narrowOop* field, oop new_val) {};100public:101102// ...then the post-write version.103inline void write_ref_field(void* field, oop new_val, bool release = false);104protected:105virtual void write_ref_field_work(void* field, oop new_val, bool release = false) = 0;106public:107108// Invoke the barrier, if any, necessary when writing the "bytes"-byte109// value(s) "val1" (and "val2") into the primitive "field".110virtual void write_prim_field(HeapWord* field, size_t bytes,111juint val1, juint val2) = 0;112113// Operations on arrays, or general regions (e.g., for "clone") may be114// optimized by some barriers.115116// The first six operations tell whether such an optimization exists for117// the particular barrier.118virtual bool has_read_ref_array_opt() = 0;119virtual bool has_read_prim_array_opt() = 0;120virtual bool has_write_ref_array_pre_opt() { return true; }121virtual bool has_write_ref_array_opt() = 0;122virtual bool has_write_prim_array_opt() = 0;123124virtual bool has_read_region_opt() = 0;125virtual bool has_write_region_opt() = 0;126127// These operations should assert false unless the correponding operation128// above returns true. Otherwise, they should perform an appropriate129// barrier for an array whose elements are all in the given memory region.130virtual void read_ref_array(MemRegion mr) = 0;131virtual void read_prim_array(MemRegion mr) = 0;132133// Below length is the # array elements being written134virtual void write_ref_array_pre(oop* dst, int length,135bool dest_uninitialized = false) {}136virtual void write_ref_array_pre(narrowOop* dst, int length,137bool dest_uninitialized = false) {}138// Below count is the # array elements being written, starting139// at the address "start", which may not necessarily be HeapWord-aligned140virtual void write_ref_array(HeapWord* start, size_t count);141142// Static versions, suitable for calling from generated code;143// count is # array elements being written, starting with "start",144// which may not necessarily be HeapWord-aligned.145static void static_write_ref_array_pre(HeapWord* start, size_t count);146static void static_write_ref_array_post(HeapWord* start, size_t count);147148protected:149virtual void write_ref_array_work(MemRegion mr) = 0;150public:151virtual void write_prim_array(MemRegion mr) = 0;152153virtual void read_region(MemRegion mr) = 0;154155// (For efficiency reasons, this operation is specialized for certain156// barrier types. Semantically, it should be thought of as a call to the157// virtual "_work" function below, which must implement the barrier.)158inline void write_region(MemRegion mr);159protected:160virtual void write_region_work(MemRegion mr) = 0;161public:162163// Some barrier sets create tables whose elements correspond to parts of164// the heap; the CardTableModRefBS is an example. Such barrier sets will165// normally reserve space for such tables, and commit parts of the table166// "covering" parts of the heap that are committed. The constructor is167// passed the maximum number of independently committable subregions to168// be covered, and the "resize_covoered_region" function allows the169// sub-parts of the heap to inform the barrier set of changes of their170// sizes.171BarrierSet(int max_covered_regions) :172_max_covered_regions(max_covered_regions) {}173174// Inform the BarrierSet that the the covered heap region that starts175// with "base" has been changed to have the given size (possibly from 0,176// for initialization.)177virtual void resize_covered_region(MemRegion new_region) = 0;178179// If the barrier set imposes any alignment restrictions on boundaries180// within the heap, this function tells whether they are met.181virtual bool is_aligned(HeapWord* addr) = 0;182183// Print a description of the memory for the barrier set184virtual void print_on(outputStream* st) const = 0;185};186187#endif // SHARE_VM_MEMORY_BARRIERSET_HPP188189190