Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/memory/barrierSet.hpp
48773 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,42Other,43Uninit44};4546enum Flags {47None = 0,48TargetUninitialized = 149};50protected:51int _max_covered_regions;52Name _kind;5354public:5556BarrierSet() { _kind = Uninit; }57// To get around prohibition on RTTI.58BarrierSet::Name kind() { return _kind; }59virtual bool is_a(BarrierSet::Name bsn) = 0;6061// These operations indicate what kind of barriers the BarrierSet has.62virtual bool has_read_ref_barrier() = 0;63virtual bool has_read_prim_barrier() = 0;64virtual bool has_write_ref_barrier() = 0;65virtual bool has_write_ref_pre_barrier() = 0;66virtual bool has_write_prim_barrier() = 0;6768// These functions indicate whether a particular access of the given69// kinds requires a barrier.70virtual bool read_ref_needs_barrier(void* field) = 0;71virtual bool read_prim_needs_barrier(HeapWord* field, size_t bytes) = 0;72virtual bool write_prim_needs_barrier(HeapWord* field, size_t bytes,73juint val1, juint val2) = 0;7475// The first four operations provide a direct implementation of the76// barrier set. An interpreter loop, for example, could call these77// directly, as appropriate.7879// Invoke the barrier, if any, necessary when reading the given ref field.80virtual void read_ref_field(void* field) = 0;8182// Invoke the barrier, if any, necessary when reading the given primitive83// "field" of "bytes" bytes in "obj".84virtual void read_prim_field(HeapWord* field, size_t bytes) = 0;8586// Invoke the barrier, if any, necessary when writing "new_val" into the87// ref field at "offset" in "obj".88// (For efficiency reasons, this operation is specialized for certain89// barrier types. Semantically, it should be thought of as a call to the90// virtual "_work" function below, which must implement the barrier.)91// First the pre-write versions...92template <class T> inline void write_ref_field_pre(T* field, oop new_val);93private:94// Keep this private so as to catch violations at build time.95virtual void write_ref_field_pre_work( void* field, oop new_val) { guarantee(false, "Not needed"); };96protected:97virtual void write_ref_field_pre_work( oop* field, oop new_val) {};98virtual void write_ref_field_pre_work(narrowOop* field, oop new_val) {};99public:100101// ...then the post-write version.102inline void write_ref_field(void* field, oop new_val, bool release = false);103protected:104virtual void write_ref_field_work(void* field, oop new_val, bool release = false) = 0;105public:106107// Invoke the barrier, if any, necessary when writing the "bytes"-byte108// value(s) "val1" (and "val2") into the primitive "field".109virtual void write_prim_field(HeapWord* field, size_t bytes,110juint val1, juint val2) = 0;111112// Operations on arrays, or general regions (e.g., for "clone") may be113// optimized by some barriers.114115// The first six operations tell whether such an optimization exists for116// the particular barrier.117virtual bool has_read_ref_array_opt() = 0;118virtual bool has_read_prim_array_opt() = 0;119virtual bool has_write_ref_array_pre_opt() { return true; }120virtual bool has_write_ref_array_opt() = 0;121virtual bool has_write_prim_array_opt() = 0;122123virtual bool has_read_region_opt() = 0;124virtual bool has_write_region_opt() = 0;125126// These operations should assert false unless the correponding operation127// above returns true. Otherwise, they should perform an appropriate128// barrier for an array whose elements are all in the given memory region.129virtual void read_ref_array(MemRegion mr) = 0;130virtual void read_prim_array(MemRegion mr) = 0;131132// Below length is the # array elements being written133virtual void write_ref_array_pre(oop* dst, int length,134bool dest_uninitialized = false) {}135virtual void write_ref_array_pre(narrowOop* dst, int length,136bool dest_uninitialized = false) {}137// Below count is the # array elements being written, starting138// at the address "start", which may not necessarily be HeapWord-aligned139inline void write_ref_array(HeapWord* start, size_t count);140141// Static versions, suitable for calling from generated code;142// count is # array elements being written, starting with "start",143// which may not necessarily be HeapWord-aligned.144static void static_write_ref_array_pre(HeapWord* start, size_t count);145static void static_write_ref_array_post(HeapWord* start, size_t count);146147protected:148virtual void write_ref_array_work(MemRegion mr) = 0;149public:150virtual void write_prim_array(MemRegion mr) = 0;151152virtual void read_region(MemRegion mr) = 0;153154// (For efficiency reasons, this operation is specialized for certain155// barrier types. Semantically, it should be thought of as a call to the156// virtual "_work" function below, which must implement the barrier.)157inline void write_region(MemRegion mr);158protected:159virtual void write_region_work(MemRegion mr) = 0;160public:161162// Some barrier sets create tables whose elements correspond to parts of163// the heap; the CardTableModRefBS is an example. Such barrier sets will164// normally reserve space for such tables, and commit parts of the table165// "covering" parts of the heap that are committed. The constructor is166// passed the maximum number of independently committable subregions to167// be covered, and the "resize_covoered_region" function allows the168// sub-parts of the heap to inform the barrier set of changes of their169// sizes.170BarrierSet(int max_covered_regions) :171_max_covered_regions(max_covered_regions) {}172173// Inform the BarrierSet that the the covered heap region that starts174// with "base" has been changed to have the given size (possibly from 0,175// for initialization.)176virtual void resize_covered_region(MemRegion new_region) = 0;177178// If the barrier set imposes any alignment restrictions on boundaries179// within the heap, this function tells whether they are met.180virtual bool is_aligned(HeapWord* addr) = 0;181182// Print a description of the memory for the barrier set183virtual void print_on(outputStream* st) const = 0;184};185186#endif // SHARE_VM_MEMORY_BARRIERSET_HPP187188189